﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Odbc;
using System.Data;

public partial class CheckNoOfResponsesUI : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        Master.FindControl("MainMenuAdmin").Visible = true;

        if ((String)Session["Username"] == null || (String)Session["Username"] != "admin")
        {
            //Response.End();
            Response.Redirect("~/LoginAdmin.aspx");
        }

        if (Page.IsPostBack == false)
        {

            String sql = "Select Course_ID, Course_Name, Feedback_ID from course_feedback";
            DataSet dataSet = new DataSet();

            DbUtilities getList = new DbUtilities(sql);
            dataSet = getList.retrieveInfo();

            for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
            {
                dataSet.Tables[0].Rows[i][0] = " " + (String)dataSet.Tables[0].Rows[i].ItemArray[0] + " " + (String)dataSet.Tables[0].Rows[i].ItemArray[1];
            }
            //DeleteRadioButtonList = new RadioButtonList();

            CheckResponseButtonList.DataSource = dataSet;
            CheckResponseButtonList.DataTextField = "Course_ID";
            CheckResponseButtonList.DataValueField = "Feedback_ID";
            CheckResponseButtonList.DataBind();
            //DeleteRadioButtonList.Enabled = true;
        }

    }

    protected void checkResponseButton_Click(object sender, EventArgs e)
    {
        if (CheckResponseButtonList.SelectedIndex == -1)
        {
            Response.Write("<Script language=javascript>alert('Please select an option!')</Script>");
            return;
        }

        String feedbackID = CheckResponseButtonList.SelectedItem.Value;
        FeedbackForm feedback = new FeedbackForm();
        int numberResponses = feedback.checkNumberResponse(feedbackID);
        if (numberResponses == -1)
        {
            Response.Write("<Script language=javascript>alert('Some Error Occured. Cannot display the results now.')</Script>");
            return;
        }
        String alertMessage = "<Script language=javascript>alert('There are currently ";
        alertMessage += numberResponses;
        alertMessage += " responses.')</Script>";
        Response.Write(alertMessage);
    }
}